/*
 * RRSView.java
 * This form is the main for that controls the users 
 * operations.
 */

package rrs;

 
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
 /**
 * The application's main frame.
 */
public class RRSView extends FrameView 
{
    public RRSView(SingleFrameApplication app) 
    {
        super(app);
        initComponents();
            btnReports.setVisible(false);
            btnPurchase.setVisible(false);
            btnReturn.setVisible(false);
            lblSelect.setVisible(false);
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();       
    }    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statusPanel = new javax.swing.JPanel();
        lblSelect = new javax.swing.JLabel();
        btnReports = new javax.swing.JButton();
        btnReturn = new javax.swing.JButton();
        btnPurchase = new javax.swing.JButton();
        btnInit = new javax.swing.JButton();
        TxtFile = new javax.swing.JTextField();
        lblMessage = new javax.swing.JLabel();

        statusPanel.setMaximumSize(new java.awt.Dimension(5000, 5000));
        statusPanel.setName("statusPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(rrs.RRSApp.class).getContext().getResourceMap(RRSView.class);
        lblSelect.setText(resourceMap.getString("lblSelect.text")); // NOI18N
        lblSelect.setName("lblSelect"); // NOI18N

        btnReports.setText(resourceMap.getString("btnReports.text")); // NOI18N
        btnReports.setAutoscrolls(true);
        btnReports.setEnabled(false);
        btnReports.setName("btnReports"); // NOI18N
        btnReports.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnReportsMouseClicked(evt);
            }
        });

        btnReturn.setText(resourceMap.getString("btnReturn.text")); // NOI18N
        btnReturn.setAutoscrolls(true);
        btnReturn.setEnabled(false);
        btnReturn.setName("btnReturn"); // NOI18N
        btnReturn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnReturnMouseClicked(evt);
            }
        });

        btnPurchase.setText(resourceMap.getString("btnPurchase.text")); // NOI18N
        btnPurchase.setAutoscrolls(true);
        btnPurchase.setEnabled(false);
        btnPurchase.setName("btnPurchase"); // NOI18N
        btnPurchase.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPurchaseMouseClicked(evt);
            }
        });

        btnInit.setText(resourceMap.getString("btnInit.text")); // NOI18N
        btnInit.setAutoscrolls(true);
        btnInit.setName("btnInit"); // NOI18N
        btnInit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnInitMouseClicked(evt);
            }
        });

        TxtFile.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        TxtFile.setText(resourceMap.getString("TxtFile.text")); // NOI18N
        TxtFile.setName("TxtFile"); // NOI18N

        lblMessage.setFont(resourceMap.getFont("lblMessage.font")); // NOI18N
        lblMessage.setText(resourceMap.getString("lblMessage.text")); // NOI18N
        lblMessage.setName("lblMessage"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(lblMessage)
                .addContainerGap())
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(TxtFile, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(lblSelect)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnReports, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnReturn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnPurchase, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnInit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(93, 93, 93))
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnInit)
                    .addComponent(TxtFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addComponent(btnPurchase)
                .addGap(21, 21, 21)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnReturn)
                    .addComponent(lblSelect))
                .addGap(19, 19, 19)
                .addComponent(btnReports)
                .addGap(26, 26, 26)
                .addComponent(lblMessage)
                .addContainerGap(38, Short.MAX_VALUE))
        );

        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

   /*
    *The Initial button was clicked
    * if the file entered is returns true the
    * enable the other buttons and make them visible
    */
private void btnInitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnInitMouseClicked
    //If read the Initalization file is true then enable the other buttons    
    String textFile = TxtFile.getText().toString();
    if (SystemInitialize.initialize(textFile))
    {
    btnInit.setEnabled(false);
    btnPurchase.setVisible(true);
    btnReturn.setVisible(true);
    btnReports.setVisible(true);
    btnPurchase.setEnabled(true);
    btnReturn.setEnabled(true);
    btnReports.setEnabled(true);
    btnInit.setVisible(false);
    TxtFile.setVisible(false);
    lblSelect.setVisible(true);
    lblMessage.setText("");
    }
    else
    {
        lblMessage.setText("This file is not available.");
    }
}//GEN-LAST:event_btnInitMouseClicked

/*
 * The pruchase button was clicked. Go to the purchase screen
 */ 
//Unable to move brackets for autogenerated event declarations
private void btnPurchaseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPurchaseMouseClicked
    if (btnPurchase.isEnabled()==true)
    {        
    purchaseForm =  new Purchase();
    purchaseForm.setTitle("Purchase");
    purchaseForm.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    purchaseForm.setVisible(true);
    }
}//GEN-LAST:event_btnPurchaseMouseClicked

//Unable to move brackets for autogenerated event declarations
private void btnReturnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnReturnMouseClicked
    if (btnReturn.isEnabled() ==true)
    {
    returnForm =  new Return();
    returnForm.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    returnForm.setTitle("Return");
    returnForm.setVisible(true); 
    }
}//GEN-LAST:event_btnReturnMouseClicked

//Unable to move brackets for autogenerated event declarations
private void btnReportsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnReportsMouseClicked
    if (btnReports.isEnabled() ==true)
    {
    reportForm = new Reports();
    reportForm.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    reportForm.setTitle("Reports");
    reportForm.setVisible(true);
    }
}//GEN-LAST:event_btnReportsMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JTextField TxtFile;
    javax.swing.JButton btnInit;
    javax.swing.JButton btnPurchase;
    javax.swing.JButton btnReports;
    javax.swing.JButton btnReturn;
    javax.swing.JLabel lblMessage;
    javax.swing.JLabel lblSelect;
    javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    //This section has been added
    public Purchase purchaseForm; 
    public Return returnForm;
    public Reports reportForm; 
}
